//
//  CornerButtonVC.swift
//  SwiftLearning
//
//  Created by 黄龙 on 2024/1/31.
//

import UIKit

class CornerButtonVC: BasicNavibarVC {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.rightBar.title = ""
    }

    override func initView() {
        let image = UIImage(systemName: "sun.max.fill")?.withTintColor(.label,renderingMode: .alwaysOriginal)
        var iTop = 15
        let btnWidth = 180
        let btnHeight = 50
        let button_1 = UIButton(frame: CGRect(x: 15, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_1)
        button_1.backgroundColor = .systemPink
        button_1.setTitle("左上圆角", for: .normal)
        button_1.setTitleColor(.label, for: .normal)
        button_1.titleLabel?.font = .systemFont(ofSize: 16)
//        button_1.layer.cornerRadius = 6
        button_1.setImage(image, for: .normal)
        button_1.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_1.easyRoundRect(corner: .topLeft, radii: CGSize(width: 6, height: 6))
        
        let button_2 = UIButton(frame: CGRect(x: btnWidth+30, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_2)
        button_2.backgroundColor = .systemPink
        button_2.setTitle("右上圆角", for: .normal)
        button_2.setTitleColor(.label, for: .normal)
        button_2.titleLabel?.font = .systemFont(ofSize: 16)
//        button_2.layer.cornerRadius = 6
        button_2.setImage(image, for: .normal)
        button_2.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_2.easyRoundRect(corner: .topRight, radii: CGSize(width: 6, height: 6))
        
        iTop += btnHeight + 15
        let button_3 = UIButton(frame: CGRect(x: 15, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_3)
        button_3.backgroundColor = .systemPink
        button_3.setTitle("左下圆角", for: .normal)
        button_3.setTitleColor(.label, for: .normal)
        button_3.titleLabel?.font = .systemFont(ofSize: 16)
//        button_3.layer.cornerRadius = 6
        button_3.setImage(image, for: .normal)
        button_3.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_3.easyRoundRect(corner: .bottomLeft, radii: CGSize(width: 6, height: 6))
        
        let button_4 = UIButton(frame: CGRect(x: btnWidth+30, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_4)
        button_4.backgroundColor = .systemPink
        button_4.setTitle("右下圆角", for: .normal)
        button_4.setTitleColor(.label, for: .normal)
        button_4.titleLabel?.font = .systemFont(ofSize: 16)
//        button_4.layer.cornerRadius = 6
        button_4.setImage(image, for: .normal)
        button_4.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_4.easyRoundRect(corner: .bottomRight, radii: CGSize(width: 6, height: 6))
        
        iTop += btnHeight + 15
        let button_5 = UIButton(frame: CGRect(x: 15, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_5)
        button_5.backgroundColor = .systemPink
        button_5.setTitle("顶部圆角", for: .normal)
        button_5.setTitleColor(.label, for: .normal)
        button_5.titleLabel?.font = .systemFont(ofSize: 16)
//        button_5.layer.cornerRadius = 6
        button_5.setImage(image, for: .normal)
        button_5.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_5.easyRoundRect(corner: [.topLeft,.topRight], radii: CGSize(width: 6, height: 6))
        
        let button_6 = UIButton(frame: CGRect(x: btnWidth+30, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_6)
        button_6.backgroundColor = .systemPink
        button_6.setTitle("底部圆角", for: .normal)
        button_6.setTitleColor(.label, for: .normal)
        button_6.titleLabel?.font = .systemFont(ofSize: 16)
//        button_6.layer.cornerRadius = 6
        button_6.setImage(image, for: .normal)
        button_6.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_6.easyRoundRect(corner: [.bottomLeft,.bottomRight], radii: CGSize(width: 6, height: 6))
        
        iTop += btnHeight + 15
        let button_7 = UIButton(frame: CGRect(x: 15, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_7)
        button_7.backgroundColor = .systemPink
        button_7.setTitle("对角圆角", for: .normal)
        button_7.setTitleColor(.label, for: .normal)
        button_7.titleLabel?.font = .systemFont(ofSize: 16)
//        button_7.layer.cornerRadius = 6
        button_7.setImage(image, for: .normal)
        button_7.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_7.easyRoundRect(corner: [.topLeft,.bottomRight], radii: CGSize(width: 6, height: 6))
        
        let button_8 = UIButton(frame: CGRect(x: btnWidth+30, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_8)
        button_8.backgroundColor = .systemPink
        button_8.setTitle("三角圆角", for: .normal)
        button_8.setTitleColor(.label, for: .normal)
        button_8.titleLabel?.font = .systemFont(ofSize: 16)
//        button_8.layer.cornerRadius = 6
        button_8.setImage(image, for: .normal)
        button_8.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        button_8.easyRoundRect(corner: [.topLeft,.topRight,.bottomLeft], radii: CGSize(width: 6, height: 6))
        
        iTop += btnHeight + 35
        let button_9 = UIButton(frame: CGRect(x: 15, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_9)
//        button_9.backgroundColor = .systemPink
        button_9.setTitle("虚框圆角1", for: .normal)
        button_9.setTitleColor(.label, for: .normal)
        button_9.titleLabel?.font = .systemFont(ofSize: 16)
        button_9.setImage(image, for: .normal)
        button_9.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        let _ = button_9.addDashdeBorderLayer(lineFrame: button_9.bounds, color: .systemGreen, lineWidth: 0.5,cornerRadius: 6.0)
        
        let button_a = UIButton(frame: CGRect(x: btnWidth+30, y: iTop, width: btnWidth, height: btnHeight))
        workView.addSubview(button_a)
        button_a.setTitle("虚框圆角2", for: .normal)
        button_a.setTitleColor(.label, for: .normal)
        button_a.titleLabel?.font = .systemFont(ofSize: 16)
        button_a.setImage(image, for: .normal)
        button_a.addActionWithBlock { [weak self](sender) in
            self?.title = sender.title(for: .normal)
        }
        let _ = button_a.addDashdeBorderLayer(lineFrame: button_a.bounds, color: .systemYellow, lineWidth: 0.5,cornerRadius: 6.0,fillColor: UIColor.systemPink.cgColor)
        if let imgView = button_a.imageView{
            button_a.bringSubviewToFront(imgView) //即使是insertLayer到底部，也会遮盖image，故将image强制置前
        }
    }

}
